package com.sliface.web.core;

import java.lang.reflect.Method;

import com.sliface.web.app.Facade;

public class FacadeProfile {
	private static MethodProfile[] methodProfileArray;

	public static MethodProfile[] extract() {

		if (methodProfileArray == null) {
			Class cl = Facade.class;
			Method[] methods = cl.getDeclaredMethods();
			int targetAcount = 0;
			for (Method item : methods) {
				if (item.getModifiers() == 1) {
					targetAcount++;
				}
			}
			methodProfileArray = new MethodProfile[targetAcount];
			targetAcount=0;
			for (int i = 0; i < methods.length; i++) {
				if (methods[i].getModifiers() == 1) {
					methodProfileArray[targetAcount] = new MethodProfile();
					methodProfileArray[targetAcount].setMethodClassName(methods[i].getName());
					Class[] parameterTypes = methods[i].getParameterTypes();
					String[] ParamsClassNameArray = new String[parameterTypes.length];
					for (int j = 0; j < parameterTypes.length; j++) {
						ParamsClassNameArray[j] = parameterTypes[j].getName();
					}
					methodProfileArray[targetAcount].setParamsClassNameArray(ParamsClassNameArray);
					methodProfileArray[targetAcount].setReturnValueClassName(methods[i].getReturnType().getName());
					targetAcount++;
				}
			}
		}
		return methodProfileArray;
	}

}
